import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;

public class Dist {
        static String endFlag = ".";
        static String newLine = "\n";

        static SimpleDateFormat all = new SimpleDateFormat("yyyyMMdd HHmmss");
        static SimpleDateFormat ymd = new SimpleDateFormat("yyyyMMdd");
        static SimpleDateFormat hm = new SimpleDateFormat("HHmm");

        public static void main(String[] args) {
                String path = "./";
                //String path = "C:/";

                System.out.println("####### current time:" + all.format(new Date()));
                System.out.println("####### paste the classes...");
                try {
                        int count = 0;
                        // String[] lines = sb.toString().split(newLine);
                        String[] lines = getInputLines();

                        String strFile = null;
                        if (args.length > 0) {
                                strFile = getDistFileString(args[0]);
                        } else {
                                strFile = getDistFileString();
                        }
                        
                        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
                                        new FileOutputStream(path + strFile), "EUC-KR"));

                        System.out.println("####### writing...");
                        for (int i = 0; i < lines.length; i++) {
                                if (!lines[i].trim().equals(endFlag)) {
                                        out.write(lines[i] + newLine);
                                        count++;
                                        System.out.println(lines[i]);
                                }
                        }
                        out.flush();
                        out.close();
                        System.out.println("####### " + strFile);
                        System.out.println("####### " + count + " line(s) writen.");

                } catch (Exception e) {
                        e.printStackTrace();
                }
        }

        private static String getDistFileString() {
                Date date = new Date();

                date.setTime(date.getTime() + 1000 * 60);

                String strYmd = ymd.format(date);
                String strHm = hm.format(date);

                Integer intHhmm = Integer.parseInt(strHm);

                if (intHhmm % 2 != 0) {
                        date.setTime(date.getTime() + 1000 * 60);
                }

                return strYmd + "_" + hm.format(date) + ".list";

        }

        private static String getDistFileString(String time) {
                Date date = new Date();

                date.setTime(date.getTime() + 1000 * 60);
                String strYmd = ymd.format(date);
                return strYmd + "_" + time + ".list";

        }

        private static String[] getInputLines() {
                Scanner reader = new Scanner(System.in);
                StringBuffer sb = new StringBuffer();
                String line = "";
                do {
                        line = reader.next();
                        sb.append(line + newLine);
                } while (!line.equals(endFlag));

                String[] lines = sb.toString().split(newLine);
                ArrayList<String> rstList = new ArrayList<String>();
                for (int i = 0; i < lines.length; i++) {
                        if (!lines[i].trim().equals(endFlag)) {
                                rstList.add(lines[i]);
                        }
                }

                return rstList.toArray(new String[0]);
        }

}